var express = require('express');
var router = express.Router();

model = require('../../models/model')

router.post('/', function(req, res, next) {
  var user = req.body.user;
  var password = req.body.password;
  model.Users.findOne({
    "user": user
  }, function(err, docs) {
    if (null == docs) {
      res.send({state: 300, message: '用户名不存在'})
    } else if (docs.password != password) {
      res.send({state: 100, message: '密码错误'})
    } else if (password == '') {
      res.send({state: 400, message: '密码不为空'})
    } else {
      req.session.username = user;
      req.session.password = password;
      res.send({state: 200, message: '登录成功'})
    }
  });
});

module.exports = router;
